package com.gaswell.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaswell.common.log.LogAnnotation;
import com.gaswell.entity.Qba01;
import com.gaswell.entity.Qba01M;
import com.gaswell.entity.Qfc01;
import com.gaswell.pojo.ReciveCycleData;
import com.gaswell.pojo.ZtAlarm;
import com.gaswell.service.*;
import com.gaswell.utils.DateUtils;
import com.gaswell.utils.ObjectUtils;
import com.gaswell.utils.StatusDetect;
import com.gaswell.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.util.*;

/**
 * @ClassName ZTAlarmController
 * @Author xiaow
 * @DATE 2023/2/21 15:32
 **/


@RestController
@RequestMapping("/ztalarm")
@Api(tags = "组态报警控制器   mysql数据库")
public class ZTAlarmController {
    @Autowired
    ZtAlarmService ztAlarmService;

    @GetMapping("getByPages")
    @ApiOperation(value = "查询组态报警信息")
    @LogAnnotation(module = "组态报警控制器", operator = "查询组态报警信息")
    public Result getByPages(String userName, String jh, int current, int size) {
        Page byPage = ztAlarmService.getByPage(current, size, jh);
        return Result.success(byPage);

    }

    @GetMapping("getLastByJh")
    @ApiOperation(value = "查询最新组态报警信息")
    @LogAnnotation(module = "组态报警控制器", operator = "查询最新组态报警信息")
    public Result getLastByJh(String userName, String jh) {
        QueryWrapper<ZtAlarm> ztAlarmQueryWrapper = new QueryWrapper<>();
        ztAlarmQueryWrapper.eq("jh",jh);
        ztAlarmQueryWrapper.orderByDesc("alarmtime");
        List<ZtAlarm> list = ztAlarmService.list(ztAlarmQueryWrapper);
        return Result.success(list);

    }


    @GetMapping("getLast")
    @ApiOperation(value = "查询最新的报警信息")
    @LogAnnotation(module = "组态报警控制器", operator = "查询最新的报警信息")
    public Result getByPages(String userName, String jh) {
        List last = ztAlarmService.getLast(jh);
        return Result.success(last);
    }

}
